home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / pao / etc / bat_tool / timewait.c < prev    next >
Text File  |  1994-06-01  |  1KB  |  57 lines

  1. #include <stdio.h>        /*  printf            */
  2. #include <stdlib.h>        /*  exit,atoi        */
  3. #include <time.h>        /*  clock,CLK_TCK    */
  4. #include <conio.h>        /*  kbhit            */
  5. #include <dos.h>        /*  bdos            */
  6.  
  7. int wait1sec( int cnt )
  8. {
  9.     clock_t st=clock(), elaps, sec, oldsec=-1 ;
  10.     int        ret=0 ;
  11.  
  12.     printf( "\x1b[33mあと      秒" ) ;
  13.     printf( "\x1b[m   ( キー入力( ESC:RET=1, その他:RET=0 )で, 終了します. )" ) ;
  14.     printf( "\x1b[33m" ) ;
  15.     do {
  16.         if ( kbhit() ) {
  17.             if ( getch() == 0x1B ) ret = 1 ;
  18.             bdos( 0x0C,0,0 ) ;
  19.             break ;
  20.         }
  21.         elaps = clock() - st ;
  22.         if ( elaps < 0 ) elaps *= (clock_t)-1 ;
  23.         elaps /= CLK_TCK ;
  24.         sec = cnt - elaps ;
  25.         if ( oldsec != sec ) {
  26.             printf( "\rあと %4d 秒 ",sec ) ;
  27.             oldsec = sec ;
  28.         }
  29.     } while ( elaps < cnt ) ;
  30.     return ret ;
  31. }
  32.  
  33. void usage( void )
  34. {
  35.     printf( "Usage: timewait 待ち時間[秒単位]\n" ) ;
  36.     printf( "                0 ~ 3600\n" ) ;
  37.     exit( -1 ) ;
  38. }
  39.  
  40. int main( int ac,char *av[] )
  41. {
  42.     int        waitcnt, ret ;
  43.  
  44.     printf( "時間待ちプログラム (C) パオパオ 1994.\n" ) ;
  45.     if ( ac != 2 ) usage() ;
  46.     waitcnt = atoi( av[1] ) ;
  47.     if ( waitcnt < 0 || waitcnt > 3600 ) usage() ;
  48.     if ( !( ret = wait1sec( waitcnt ) ) ) {
  49.         printf( "\x1b[m\rプログラムを終了します." ) ;
  50.     } else {
  51.         printf( "\x1b[m\rプログラムを中断します." ) ;
  52.     }
  53.     printf( "                                               \n" ) ;
  54.     return ret ;
  55. }
  56.  
  57.